package BD;


import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.DaoManagerBuilder;

import java.io.Reader;


/**
 * @version    1.0, 16/12/2009
 * @author     Dennis Risco
 * @since      1.0
 */
public class DaoConfig {
    private static final String resource =
        "BD/dao.xml";
    private static final DaoManager daoManager;

    /**
     * <b>Uso:</b> Inicializa variables est�ticas.
     */
    static {
        try {
            daoManager = newDaoManager();
            
        } catch (Exception e) {
            throw new RuntimeException("Description.  Cause: " + e, e);
        }

    }

    /**
     * <b>Uso:</b> Obtiene el objeto administraci�n de datos.
     * @return daoManager Objeto de administraci�n de datos.
     */
    public static DaoManager getDaoManager() {
        return daoManager;
    }

    /**
     * <b>Uso:</b> Inicializa y devuelve el objeto de administraci�n de datos.
     * @return dao Objeto de administraci�n de datos.
     */
    public static DaoManager newDaoManager() {
        try {
            Reader reader = Resources.getResourceAsReader(resource);              
            DaoManager dao = DaoManagerBuilder.buildDaoManager(reader,null);            
            return dao;
        } catch (Exception e) {
            throw new RuntimeException("Could not initialize DaoConfig.  Cause: " +
                                       e, e);
        }
    }
}
